package material.strategy;

/**
 * 鸭子的父类
 */
public abstract class Duck {
    QuackBehavior quackBehavior;//负责叫
    FlyBeahavior flyBeahavior;//负责飞

    public Duck() {
    }

    public void performFly() {
        flyBeahavior.fly();
    }

    public void performQuack() {
        quackBehavior.quack();//鸭子对象不用亲自处理咕咕叫的行为，而是委托给quackBehavior引用的对象
    }

    public void swim() {
        System.out.println("所有的鸭子都会游泳，即使是橡皮鸭");
    }

    public void display() {

    }
    /**动态设定**/
    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    public void setFlyBeahavior(FlyBeahavior flyBeahavior) {
        this.flyBeahavior = flyBeahavior;
    }
}
